// pages/mine/CompanyHomepage/CompanyHomepage.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    winHeight: "", //窗口高度
    currentTab: 0, //预设当前项的值
    scrollLeft: 0, //tab标题的滚动条位置
    toView: 'red',
    scrollTop: 100,
    currentIndex: 0,
    company: {},
    company_platfrom: [],
    company_anchor: [],
    company_photo: [],

    //职位
    resume: [],
    img_logo: 'https://www.zhibohome.net/images/CompanyHome/gsjs_mrtb.png',

    // 传参
    token:'',
  },
  //详情
  go_detail: function (e) {
    console.log(e.currentTarget.dataset.deatil_id)
    let deatil_id = e.currentTarget.dataset.deatil_id;
    wx.navigateTo({
      url: '../../../recruit/detail/detail?deatil_id=' + deatil_id,
    })
  },
  //获取热招列表
  recruitList() {
    let that = this;
    wx.request({
      url: app.globalData.url + 'api/company/hot/position',
      data: {
        token: that.data.token,
      },
      method: 'POST',
      success: function (e) {
        console.log(e)
        let resume = e.data.data.list.data
        that.setData({
          resume: resume,
        })
      }
    })
  },
  // 滚动切换标签样式
  switchTab: function (e) {
    var winWid = wx.getSystemInfoSync().windowWidth;
    switch (e.detail.current) {
      case 0:
        var query = wx.createSelectorQuery();
        //选择id
        var that = this;
        query.select('.scoll-height').boundingClientRect(function (rect) {
          var imgh = rect.height; //图片高度
          var imgw = rect.width; //图片宽度
          var swiperH = winWid * imgh / imgw + "px"
          that.setData({
            winHeight: swiperH
          });
        }).exec();
        break;
      case 1:
        var query = wx.createSelectorQuery();
        //选择id
        var that = this;
        query.select('.scoll-heights').boundingClientRect(function (rect) {
          var imgh = rect.height; //图片高度
          var imgw = rect.width; //图片宽度
          var swiperH = winWid * imgh / imgw + "px"
          that.setData({
            winHeight: swiperH
          });
        }).exec();
        break;
      case 2:
        var query = wx.createSelectorQuery();
        //选择id
        var that = this;
        query.select('.scoll-heightd').boundingClientRect(function (rect) {
          var imgh = rect.height; //图片高度
          var imgw = rect.width; //图片宽度
          var swiperH = winWid * imgh / imgw + "px"
          that.setData({
            winHeight: swiperH
          });
        }).exec();
        break;
    }
    this.setData({
      currentTab: e.detail.current
    });
    this.checkCor();
  },
  // 点击标题切换当前页时改变样式
  swichNav: function (e) {
    var winWid = wx.getSystemInfoSync().windowWidth;
    var cur = e.target.dataset.current;
    switch (cur) {
      case '0':
        var query = wx.createSelectorQuery();
        //选择id
        var that = this;
        query.select('.scoll-height').boundingClientRect(function (rect) {
          var imgh = rect.height; //图片高度
          var imgw = rect.width; //图片宽度
          var swiperH = winWid * imgh / imgw + "px"
          that.setData({
            winHeight: swiperH
          });
        }).exec();
        break;
      case '1':
        var query = wx.createSelectorQuery();
        //选择id
        var that = this;
        query.select('.scoll-heights').boundingClientRect(function (rect) {
          var imgh = rect.height; //图片高度
          var imgw = rect.width; //图片宽度
          var swiperH = winWid * imgh / imgw + "px"
          that.setData({
            winHeight: swiperH
          });
        }).exec();
        break;
      case '2':
        var query = wx.createSelectorQuery();
        //选择id
        var that = this;
        query.select('.scoll-heightd').boundingClientRect(function (rect) {
          var imgh = rect.height; //图片高度
          var imgw = rect.width; //图片宽度
          var swiperH = winWid * imgh / imgw + "px"
          that.setData({
            winHeight: swiperH
          });
        }).exec();
        break;
    }
    if (this.data.currentTaB == cur) {
      return false;
    } else {
      this.setData({
        currentTab: cur
      })
    }

  },
  //判断当前滚动超过一屏时，设置tab标题滚动条。
  checkCor: function () {
    if (this.data.currentTab > 4) {
      this.setData({
        scrollLeft: 300
      })
    } else {
      this.setData({
        scrollLeft: 0
      })
    }
  },
  // 初始高度状态
  companyHeight() {
    var that = this;
    var winWid = wx.getSystemInfoSync().windowWidth;
    //高度自适应
    var query = wx.createSelectorQuery();
    //选择id
    query.select('.scoll-height').boundingClientRect(function (rect) {
      var imgh = rect.height; //图片高度
      var imgw = rect.width; //图片宽度
      var swiperH = winWid * imgh / imgw + "px"
      that.setData({
        winHeight: swiperH
      });
    }).exec();
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    let token = options.token;
    this.setData({
      token: token,
    })
    var that = this;
    wx.request({
      method: 'POST',
      url: app.globalData.url + 'api/company/index',
      data: {
        token: that.data.token
      },
      success: function (e) {
        that.setData({
          company: e.data.data.company,
          company_platfrom: e.data.data.company_platfrom,
          company_anchor: e.data.data.company_anchor,
          company_photo: e.data.data.company_photo
        })
        that.companyHeight();
      }
    })
  },
  handleChange: function (e) {
    this.setData({
      currentIndex: e.detail.current
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.recruitList();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})